# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

package(default_visibility = ["//visibility:public"])

load(":cc_toolchain_config.bzl", "coralnpu_v2_cc_toolchain_config")

filegroup(
    name = "all_files",
    srcs = [
        "//toolchain/wrappers:all",
        "//toolchain:coralnpu_tcm.ld",
        "//toolchain:coralnpu_tcm_highmem.ld",
        "@toolchain_coralnpu_v2//:all_files",
    ],
)

coralnpu_v2_cc_toolchain_config(
    name = "coralnpu_v2_toolchain_config",
    semihosting = False,
)

coralnpu_v2_cc_toolchain_config(
    name = "coralnpu_v2_semihosting_toolchain_config",
    semihosting = True,
)

cc_toolchain(
    name = "coralnpu_v2_toolchain",
    all_files = ":all_files",
    ar_files = ":all_files",
    as_files = ":all_files",
    compiler_files = ":all_files",
    dwp_files = ":all_files",
    linker_files = ":all_files",
    objcopy_files = ":all_files",
    strip_files = ":all_files",
    supports_param_files = 0,
    toolchain_config = ":coralnpu_v2_toolchain_config",
    toolchain_identifier = "coralnpu_v2_toolchain",
)

cc_toolchain(
    name = "coralnpu_v2_semihosting_toolchain",
    all_files = ":all_files",
    ar_files = ":all_files",
    as_files = ":all_files",
    compiler_files = ":all_files",
    dwp_files = ":all_files",
    linker_files = ":all_files",
    objcopy_files = ":all_files",
    strip_files = ":all_files",
    supports_param_files = 0,
    toolchain_config = ":coralnpu_v2_semihosting_toolchain_config",
    toolchain_identifier = "coralnpu_v2_semihosting_toolchain",
)

toolchain(
    name = "cc_coralnpu_v2_toolchain",
    exec_compatible_with = [
        "@platforms//cpu:x86_64",
        "@platforms//os:linux",
    ],
    target_compatible_with = [
        "//platforms/cpu:coralnpu_v2",
        "@platforms//os:none",
    ],
    toolchain = ":coralnpu_v2_toolchain",
    toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

toolchain(
    name = "cc_coralnpu_v2_semihosting_toolchain",
    exec_compatible_with = [
        "@platforms//cpu:x86_64",
        "@platforms//os:linux",
    ],
    target_compatible_with = [
        "//platforms/cpu:coralnpu_v2",
        "//platforms/os:semihosting",
    ],
    toolchain = ":coralnpu_v2_semihosting_toolchain",
    toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

sh_binary(
    name = "gdb",
    srcs = [
        "//toolchain/wrappers:gdb",
    ],
    data = [
        ":coralnpu_v2_toolchain",
    ],
)
